package net.folab.data;

public class FTMain {

    /**
     * @param args
     */
    public static void main(String[] args) {

        Workspace workspace = new Workspace();

        final BasicTable populationTable = workspace
                .registerTable(new BasicTable("Population"));
        BasicColumn country = populationTable
                .addColumn("Country", DataType.TEXT);
        BasicColumn population = populationTable.addColumn("Population",
                DataType.INTEGER);
        populationTable.addColumn("Research Date", DataType.DATE);

        populationTable.addRow("China", 1347350000, "12/31/2011");
        populationTable.addRow("India", 1210193422, "3/1/2011");
        populationTable.addRow("United/States", 313048000, "2/20/2012");
        populationTable.addRow("Indonesia", 237641326, "5/1/2011");
        populationTable.addRow("Brazil", 192376496, "7/1/2011");
        populationTable.addRow("Pakistan", 178745000, "2/20/2012");
        populationTable.addRow("Nigeria", 162471000, "7/1/2011");
        populationTable.addRow("Russia", 143030106, "1/1/2012");
        populationTable.addRow("Bangladesh", 142319000, "3/15/2011");
        populationTable.addRow("Japan", 127770000, "2/1/2012");
        populationTable.addRow("Mexico", 112336538, "6/12/2010");

        final BasicTable oecdTable = workspace.registerTable(new BasicTable(
                "OECD"));
        oecdTable.addColumn("Country", DataType.TEXT);
        BasicColumn membershipDate = oecdTable.addColumn("Membership Date",
                DataType.DATE);

        oecdTable.addRow("Japan", "4/28/1964");
        oecdTable.addRow("South Korea", "12/12/1996");
        oecdTable.addRow("Turkey", "2/8/1961");

        FormularDataTable joinTable = new FormularDataTable("Join");
        joinTable.addJoin(populationTable.getColumn("Country"),
                oecdTable.getColumn("Country"), TableJoin.Type.INNER);
        joinTable.addColumn("Country", DataType.TEXT, new ColumnDataFormular(
                country));
        joinTable.addColumn("Population", DataType.TEXT,
                new ColumnDataFormular(population));
        joinTable.addColumn("Membership Date", DataType.TEXT,
                new ColumnDataFormular(membershipDate));

        dump(populationTable);
        dump(oecdTable);
        dump(joinTable);

    }

    public static void dump(DataTable table) {

        System.out.println("<h2>" + table.getName() + "</h2>");
        System.out.println("<table border=1>");

        System.out.println("<tr>");
        for (DataColumn column : table.getColumns()) {
            System.out.println("<th>" + column.getName() + "</th>");
        }
        System.out.println("</tr>");

        for (DataRow row : table.getRows()) {
            System.out.println("<tr>");
            for (DataCell cell : row.getCells()) {
                System.out.println("<td>" + cell.getValue() + "</td>");
            }
            System.out.println("</tr>");
        }
        System.out.println("</table>");

    }

}
